<template>
  <div>
    <el-dialog
      :visible.sync="dialogVisible.v"
      :page="currentPage"
      v-dialogDrag
      v-on:click="getGMData">
      <div>
        <v_myForm v-on:getGeeParam="getGMData" :page="modelPage" :form_list="Modelparams" :dialogVisible.sync="dialogVisible" :artifactId="artifactId" :currentItemId="currentItemId" ref="myForm"></v_myForm>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import myForm from '../form/modelForm';


  export default {
    name: "model-dialog",
    data() {
      return {
        modelPage:'',
        geeModelParams:[],
        Modelparams: [],
        formData: [],
        dialogVisible: Object,
        artifactId: '',
        currentItemId:'',
        jobName: '',
      }
    },
    components: {
      "v_myForm": myForm,
    },
    props:{
        currentPage:String
    },
    methods: {
      initParallelModel() {
        this.Modelparams=[];
        let obj=this;
        this.$axios.get(
          // url: 'http://192.168.240.25:3000/dldsj/parallel/get/' + this.artifactId,
          '/parallel/get/' + this.artifactId)
          .then((res) => {
            let modelpara=[];
            let parm = JSON.parse(res.body.parameters);
            // let geeParam = [];
            let hasPosition = false;
            for (let param of parm) {
                if (param.name.indexOf('空间范围') !== -1) {
                    hasPosition = true;
                    break;
                }
                //过滤只有一个输入数据源的参数
                // if (param.in <= 0) {
                //     continue;
                // } else {
                //     geeParam.push(param);
                // }
            }
            if(this.currentPage!=='gee'){
                if(hasPosition == true){
                    modelpara = [{"default":"default","datatype":"String","name":"任务名称","description":"一个SPARK任务的名称"}];
                }else{
                    modelpara = [{"default":"default","datatype":"String","name":"任务名称","description":"一个SPARK任务的名称"},{"default":"default","datatype":"String","name":"空间范围","description":"模型运行的空间范围"}];
                }
                this.Modelparams = modelpara.concat(JSON.parse(res.body.parameters));
            }else if(this.currentPage=='gee'){
                this.modelPage = 'gee';
                // modelpara = [{"default":"default","datatype":"String","name":"空间范围","description":"方法执行的空间范围"}];
                // this.Modelparams = modelpara.concat(geeParam);
                // this.Modelparams = JSON.parse(res.body.parameters).concat(modelpara);
                this.Modelparams = JSON.parse(res.body.parameters);
            }
          }
        ).catch(function (error) {
          console.log(error);
          obj.$message.error('模型参数获取失败!');
        });
        if (this.$refs.myForm)
            this.$refs.myForm.reset();
      },
      getGMData(data){
          this.$emit("totalModelParam",data);
      },

    },
    mounted() {
      this.$Bus.$on('pop', (dialogVisible, artificatId,currentItemId) => {
        this.dialogVisible = dialogVisible;
        this.artifactId = artificatId;
        this.currentItemId = currentItemId;
        this.initParallelModel();
      })
    },
  }
</script>
<style>
  .el-dialog__body {
    padding: 0px 20px 20px 20px;
  }
</style>
